<template>
  <!-- 商家登录 -->
  <div>
    <van-field v-model="nickname" label="名称" placeholder="名称" />
    <van-field
      v-model="password"
      type="password"
      label="密码"
      placeholder="密码"
    />
    <van-field v-model="mobile" label="手机号" placeholder="手机号" />

    <van-button type="primary" @click="submit">登录</van-button>
  </div>
</template>

<script>
export default {
  data() {
    return {
      password: "",
      nickname: "",
      mobile: "",
    };
  },
  methods: {
    // 登录
    submit: function () {
      if (this.nickname == "") {
        this.$toast.fail("名称不能为空");
        return false;
      }
      if (this.mobile == "") {
        this.$toast.fail("手机号不能为空");
        return false;
      }
      if (this.password == "") {
        this.$toast.fail("密码不能为空");
        return false;
      }
      this.myaxios(this.weburl + "user/login/", "post", {
        nickname: this.nickname,
        mobile: this.mobile,
        password: this.password,
      }).then((data) => {
        console.log("data", data);
        if (data.code == 200) {
          this.$toast.success(data.msg);

          // 登陆成功存储用户信息
          localStorage.setItem("token", data.token);
          localStorage.setItem("nickname", data.data.nickname);
          localStorage.setItem("id", data.data.id);

          // 登陆成功跳转商家个人首页 params: { id: data.data.id }
          this.id = localStorage.getItem("id");
          console.log("id", this.id);
          this.$router.push({ path: "/shopsindex/shopsinfo"});
        } else {
          this.$toast.fail(data.msg);
        }
      });
    },
  },
  created() {},
};
</script>

<style scoped>
</style>